package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.FriendModel;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by firefox on 2016/6/5.
 */
public class FindPeopleAdapter extends ListAdapter<FriendModel> {

    public FindPeopleAdapter(Context context) {
        super(context);
    }


    @Override
    public int getContentViewId() {
        return R.layout.item_message_chat;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        MessageView hold = new MessageView();
        hold.icon = (CircleImageView) contentView.findViewById(R.id.icon);
        hold.title = (TextView) contentView.findViewById(R.id.team_name);
        hold.time = (TextView) contentView.findViewById(R.id.create_time);
        hold.content = (TextView) contentView.findViewById(R.id.content);
        return hold;
    }

    @Override
    public void setItemView(int position, HolderView contentView, FriendModel item) {
        MessageView hold = (MessageView) contentView;
        if (!TextUtils.isEmpty(item.getHeadpic()) && item.getHeadpic().startsWith("http://"))
            ImageLoader.getInstance().displayImage(item.getHeadpic(), hold.icon);
        if (!TextUtils.isEmpty(item.getUsername()))
            hold.title.setText(item.getUsername());
        else
            hold.title.setText("匿名");
        if (!TextUtils.isEmpty(item.getLabels()))
            hold.content.setText(item.getLabels());
        else
            hold.content.setText("未设置");
        hold.time.setVisibility(View.GONE);
    }

    class MessageView extends HolderView {
        private CircleImageView icon;
        private TextView title;
        private TextView time;
        private TextView content;
    }
}
